package com.qf.dao.impl;

import com.qf.dao.DeveloperDao;
import com.qf.pojo.Developer;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class DeveloperDaoImpl implements DeveloperDao {
    private JdbcTemplate jdbcTemplate;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {

        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public List<Developer> findAll() {
        List<Developer> developers = jdbcTemplate.query("select * from developer", new BeanPropertyRowMapper<>(Developer.class));
        return developers;
    }

    @Override
    public void deleteDeveloper(String did) {
        int i = jdbcTemplate.update("delete from developer where did=?", did);
        int i1 = jdbcTemplate.update("update project set did=null where did=?", did);
    }
}
